package gold.digger;

import gold.utils.InputUtil;

import java.util.Arrays;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC9999Temp {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int[] dailyTemperatures(int[] arr) {
            int[] dp = new int[arr.length];
            for (int i = arr.length - 2; i >= 0; i--) {
                if (arr[i] < arr[i + 1]) dp[i] = i + 1;//存下标
                else {
                    int k = dp[i + 1];
                    while (k != 0 && arr[i] >= arr[k]) {
                        k = dp[k];
                    }
                    dp[i] = k;
                }
            }

            for (int i = arr.length - 1; i >= 0; i--) {
                dp[i] = dp[i] - i > 0 ? dp[i] - i : 0;
            }

            return dp;
        }
    }

    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[73, 74, 75, 71, 69, 72, 76, 73]");
        System.out.println(Arrays.toString(solution.dailyTemperatures(arr)));
    }

    public static void main(String[] args) throws Exception {
        LC9999Temp an = new LC9999Temp();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
